package picoevo.tutorials.simbad.robotavoidbehavior;

import picoevo.core.representation.Population;
import picoevo.ext.evolution.InitialisationOperator_Population_SimplePopulation;
import picoevo.ext.representation.Population_SimplePopulation;
import picoevo.toolbox.Display;
import simbad.gui.Simbatch;

public class InitialisationOperator_Population_SimpleAvoiderRobot extends InitialisationOperator_Population_SimplePopulation {

	// ### Constructors ###

	public InitialisationOperator_Population_SimpleAvoiderRobot() {
		super();
	}

	public InitialisationOperator_Population_SimpleAvoiderRobot(String __name) {
		super(__name);
	}

	// ### Methods ###

	@Override
	public void initialise(Population __o) {
		Population_SimplePopulation population = null;

		// 1. initialize and register individuals
		try {
			population = (Population_SimplePopulation) __o;
			super.initialise(population);
		} catch (java.lang.ClassCastException e) {
			Display.error("" + this.getClass().getName() + "::initialise(.) - Class cast exception");
		}

		// 2. create the simulation environment for evaluation purpose
		try {
			Display.info("Initialize evaluation environment.");
			population.getTemplate().setProperty("Robot", new Evaluator_SimpleAvoiderRobot());
			population.getTemplate().setProperty("Simulator", new Simbatch((Evaluator_SimpleAvoiderRobot) population.getTemplate().getObjectProperty("Robot"), true));
			((Simbatch) population.getTemplate().getObjectProperty("Simulator")).reset();
		} catch (java.lang.NullPointerException e) {
			Display.error("" + this.getClass().getName() + "::initialise(.) - null pointer exception when accessing Robot and/or Simulator");
		}
	}
}
